﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Job.Logic.Common;
using Job.Web.Framework;
using Job.Entity;
using Job.Data.Interfaces;

namespace Job.Logic.Company
{
    public class PositionLogic
    {
        //某个企业所创建的所有职位，不区分职位状态
        public int GetPositionCountByCompany(int companyId)
        {
            string sql = "Select * From job_position_info Where company_info_id = " + companyId.ToString();
            CommonLogic common = new CommonLogic();
            DataSet ds = common.GetPageDataBySql(sql, 10, 1, 1,"refresh_date", SortDirection.Descending, null);
            DataTable dt = ds.Tables[0];
            int count = Convert.ToInt32(dt.Rows[0][0]);
            return count;
        }

        //企业管理自己的职位时显示的列表
        public DataTable GetAdminPagePositionByCompany(int companyId,int pageSize,int pageIdx)
        {
            string sql = "Select position_info_id,position_name,click_num,end_date,refresh_date,cur_status "
                + "From job_position_info Where company_info_id = " + companyId.ToString();
            CommonLogic common = new CommonLogic();
            DataSet ds = common.GetPageDataBySql(sql,pageSize,pageIdx,0,
                "refresh_date",SortDirection.Descending,null);

            return ds.Tables[0];
        }

        //删除某个职位，为防止企业删除其它企业的职位，where条件为职位ID + 企业ID
        public void Delete(int company, int position)
        {
            JobPositionInfo info = new JobPositionInfo();
            info.PositionInfoId = position;
            info.CompanyInfoId = company;
            IJobPositionInfoDao dao = DataAccess.positionInfoDao;
            dao.Delete(info);
        }

        public JobPositionInfo GetPosition(int id)
        {
            return DataAccess.positionInfoDao.Find(id);
        }
        public void Insert(JobPositionInfo info)
        {
            DataAccess.positionInfoDao.Insert(info);
        }
        public void Update(JobPositionInfo info)
        {
            DataAccess.positionInfoDao.Update(info);
        }
    }
}
